package app.DAO;


import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;

import app.model.Etudiant;

public class EtudiantDAO {

	Session session;
	
	public EtudiantDAO(Session session){
	this.session = session;
	}
	
	public void creat(Etudiant e){
		session.save(e);
	}
	
	public void update(Long id, Etudiant e){
		Etudiant e1 = (Etudiant) session.get(Etudiant.class,id);
		e1.setCne(e.getCne());
		e1.setFiliere(e.getFiliere());
		e1.setNiveauEtude(e.getNiveauEtude());
		e1.setNom(e.getNom());
		e1.setPrenom(e.getPrenom());
		session.update(e1);
	}
	
	public void delete(Long id){
		session.delete((Etudiant) session.get(Etudiant.class,id));
	}
	
	public List<Etudiant> read(){
		
		return session.createQuery("from Etudiant").list();
	}
	
	public Etudiant readById(Long id){
		
		Query q = session.createQuery("from Etudiant where id= :identifiant");
		q.setLong("identifiant", id );
		return (Etudiant) q.uniqueResult();
	}
	
}
